import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import project1 from '@/components/project1/project1'
import project2 from '@/components/project2/project2'
import project3 from '@/components/project3/project3'
import project4 from '@/components/project4/project4'
import projectDetail from '@/components/projectDetail/projectDetail'
import projectList from '@/components/projectList/projectList'
import chinaMap from '@/components/chinaMap/chinaMap'
import login from '@/components/login/login'
import formList from '@/components/formList/formList'
import formDetail from '@/components/formDetail/formDetail'
import test from '@/components/test/test'

Vue.use(Router)

export default new Router({
  base: '/web/',
  mode: 'history',
  routes: [
    {
      path: '/hello',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/project1',
      name: 'project1',
      component: project1
    },
    {
      path: '/project2',
      name: 'project2',
      component: project2
    },
    {
      path: '/project3',
      name: 'project3',
      component: project3
    },
    {
      path: '/project4',
      name: 'project4',
      component: project4
    },
    {
      path: '/',
      name: 'index',
      component: project4
    },
    {
      path: '/projectList',
      name: 'projectList',
      component: projectList
    },
    {
      path: '/projectDetail',
      name: 'projectDetail',
      component: projectDetail
    },
    {
      path: '/chinaMap',
      name: 'chinaMap',
      component: chinaMap
    },
    {
      path: '/login',
      name: 'login',
      component: login
    },
    {
      path: '/formList',
      name: 'formList',
      component: formList,
      beforeEnter: (to, from, next) => {
        let userInfo = localStorage.getItem('userInfo')
        if (userInfo) {
          next()
        } else {
          next('/')
        }
      }
    },
    {
      path: '/formDetail',
      name: 'formDetail',
      component: formDetail
    },
    {
      path: '/test',
      name: 'test',
      component: test
    },
    {
      path: '*',
      name: 'err',
      component: project4
    }
  ]
})
